package com.ceres.customer.dao;

import com.ceres.customer.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Component
public interface CustUserMapper extends Mapper<User> {
    //添加一个农场主
    @Insert("insert into t_cust_user values (null,#{customerId},#{name},#{username},#{password},#{status})")
    void add(User user);

    //通过农场Id查找用户
    @Select("select * from t_cust_user where customer_id=#{id}")
    List<User> findByCustomerId(Integer id);

    //模糊查询农业组织用户
    @Select("<script>select * from t_cust_user <if test=\"keyword!=null and keyword!=''\">where name=#{keyword} or customer_id={keyword}</if></script>")
    List<User> findByKeyWord(@Param("keyword")String keyword);

    //通过用户id查找用户角色关联表
    @Select("select * from t_cust_user_role where cuid = #{id}")
    List findByUserId(int id);

    //根据userId删除用户角色关联信息
    @Delete("delete from t_cust_user_role where cuid = #{userId}")
    void deleteUserRole(Integer userId);

    //向用户角色表中添加信息
    @Insert("insert into t_cust_user_role values (#{userId},#{roleId})")
    void addRoleUser(@Param("userId")Integer userId,@Param("roleId") Integer roleId);

    //通过id修改密码
    @Update("update t_cust_user set password = #{password} where id = #{id}")
    void updatePasswordById(@Param("id")int id,@Param("password") String password);
}
